﻿// Decompiled with JetBrains decompiler
// Type: LayersParser.Objects.IfCondition
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using LayersParser.Extensions;
using LayersParser.Interfaces;
using System.Collections.Generic;
using System.Xml.Linq;


namespace LayersParser.Objects;

public class IfCondition : Common, ISublines
{
  private List<XElement> conditionnodes = new List<XElement>();
  private List<string> _condition = new List<string>();
  private List<string> _functions = new List<string>();
  private List<string> _conditionType = new List<string>();
  private int indexOfApparition;
  private List<string> parameters = new List<string>();
  private List<List<Line>> _multilines = new List<List<Line>>();
  private int boundStart;
  private int boundEnd;

  public IfCondition() => this.Node = new XElement((XName) "Type");

  public IfCondition(XElement xElement)
  {
    this.conditionnodes.Add(xElement);
    this._conditionType.Add(xElement.Name.ToString());
    this._condition.Add(xElement.FirstCDATA());
    string str = "";
    foreach (XElement element in xElement.Elements((XName) "Item"))
    {
      if (element.Value == "_")
        element.Value = " _ ";
      str += element.Value;
    }
    this._functions.Add(str);
  }

  public void ElseIfConditionCtor(XElement xElement)
  {
    this.conditionnodes.Add(xElement);
    this._conditionType.Add(xElement.Name.ToString());
    if (xElement.Name.ToString() == "ElseIf")
      this._condition.Add(xElement.FirstCDATA());
    else
      this._condition.Add("");
    string str = "";
    foreach (XElement element in xElement.Elements((XName) "Item"))
    {
      if (element.Value == "_")
        element.Value = " _ ";
      str += element.Value;
    }
    this._functions.Add(str);
  }

  public string Functions
  {
    get => this._functions[this.indexOfApparition];
    set => this._functions[this.indexOfApparition] = value;
  }

  public string ReturnConditionType() => "";

  public string Value
  {
    get => this._functions[this.indexOfApparition];
    set => this._functions[this.indexOfApparition] = value;
  }

  public XElement SublineNode
  {
    get => this.conditionnodes[this.indexOfApparition];
    set => this.conditionnodes[this.indexOfApparition] = value;
  }

  public List<string> GiveAttributes()
  {
    List<string> stringList = new List<string>();
    if (this._condition[this.indexOfApparition] != null && this._conditionType[this.indexOfApparition] != null)
      stringList.Add($"{this._conditionType[this.indexOfApparition]}: {this._condition[this.indexOfApparition]}");
    return stringList;
  }

  public List<int> Bounds
  {
    get
    {
      return new List<int>()
      {
        this.boundStart,
        this.boundEnd
      };
    }
    set
    {
      this.boundStart = value[0];
      this.boundEnd = value[1];
    }
  }

  public string ReturnText()
  {
    string str = "";
    for (int index = 0; index < this._functions.Count; ++index)
    {
      str = $"{str}{this._conditionType[index]}: {this._condition[index]}{{{this._functions[index]}}}";
      if (index != this._functions.Count - 1)
        str += "\n";
    }
    return str;
  }
}
